import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/login/registerindex'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    role: 'teacher',
    redirect: '/stu-manager',
    component: Layout,
    children: [
      {
        path: 'stu-manager',
        name: 'StuManager',
        component: () => import('@/views/teacher/stumanager/index'),
        meta: { title: '学生管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/course',
    role: 'teacher',
    component: Layout,
    redirect: '/t/course',
    name: 'Course',
    meta: { title: '课程管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/t/course',
        name: 'tCourse',
        component: () => import('@/views/teacher/course/index'),
        meta: { title: '课程类目', icon: 'form' }
      },
      {
        path: '/t/courseware',
        name: 'tCourseware',
        component: () => import('@/views/teacher/courseware/index'),
        meta: { title: '课件管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/work',
    role: 'teacher',
    component: Layout,
    redirect: '/t/work',
    name: 'Work',
    meta: { title: '作业管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/t/work',
        name: 'tWork',
        component: () => import('@/views/teacher/work/index'),
        meta: { title: '题库管理', icon: 'form' }
      },
      {
        path: '/t/workSubmit',
        name: 'tWorkSubmit',
        component: () => import('@/views/teacher/workTask/index'),
        meta: { title: '作业', icon: 'form' }
      },
      {
        path: '/t/autoPage',
        name: 'tAutoPage',
        component: () => import('@/views/teacher/readeTask/index'),
        meta: { title: '阅卷', icon: 'form' }
      }
    ]
  },
  {
    path: '/question',
    role: 'teacher',
    component: Layout,
    redirect: '/t/question',
    name: 'Question',
    meta: { title: '考试管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/t/question',
        name: 'tQuestion',
        component: () => import('@/views/teacher/question/index'),
        meta: { title: '试题管理', icon: 'form' }
      },
      {
        path: '/t/exam',
        name: 'tExam',
        component: () => import('@/views/teacher/exam/index'),
        meta: { title: '考试管理', icon: 'form' }
      },
      {
        path: '/t/chengji',
        name: 'Chengji',
        hidden: true,
        component: () => import('@/views/teacher/achievement/index'),
        meta: { title: '科目成绩', icon: 'form' }
      }
    ]
  },
  {
    path: '/t/discuss',
    role: 'teacher',
    component: Layout,
    children: [
      {
        path: '/t/discuss',
        name: 'tDiscuss',
        component: () => import('@/views/teacher/discuss/index'),
        meta: { title: '讨论管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/t/feedback',
    role: 'teacher',
    component: Layout,
    children: [
      {
        path: '/t/feedback',
        name: 'tFeedback',
        component: () => import('@/views/teacher/feedback/index'),
        meta: { title: '反馈管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/resource',
    role: 'teacher',
    component: Layout,
    redirect: '/t/resource',
    name: 'Resource',
    meta: { title: '资源管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/t/resource',
        name: 'resource',
        component: () => import('@/views/teacher/resource/index'),
        meta: { title: '教育资源', icon: 'form' }
      },
      {
        path: '/t/simi_resource',
        name: 'simi_resource',
        component: () => import('@/views/teacher/simi_resource/index'),
        meta: { title: '个性化资源', icon: 'form' }
      }

    ]
  },

  {
    path: '/t/info',
    role: 'teacher',
    hidden: true,
    component: Layout,
    children: [
      {
        path: '/t/info',
        name: 'tInfo',
        component: () => import('@/views/teacher/info/index'),
        meta: { title: '个人中心', icon: 'form' }
      }
    ]
  },
  {
    path: '/t/changePass',
    role: 'teacher',
    hidden: true,
    component: Layout,
    children: [
      {
        path: '/t/changePass',
        name: 'tchangePass',
        component: () => import('@/views/teacher/changePass/index'),
        meta: { title: '修改密码', icon: 'form' }
      }
    ]
  },
  {
    path: '/',
    role: 'student',
    redirect: '/all',
    component: Layout,
    meta: { title: '课程管理', icon: 'form' },
    children: [
      {
        path: 'all',
        name: 'All',
        component: () => import('@/views/student/all/index'),
        meta: { title: '全部课程', icon: 'form' }
      },
      {
        path: '/owner',
        name: 'Owner',
        component: () => import('@/views/student/owner/index'),
        meta: { title: '我的课程', icon: 'form' }
      }
    ]
  },
  {
    path: '/stu',
    role: 'student',
    redirect: '/stu',
    component: Layout,
    meta: { title: '学习资源', icon: 'form' },
    children: [
      // {
      //   path: 'edu-res',
      //   name: 'EduRes',
      //   component: () => import('@/views/student/edures/index'),
      //   meta: { title: '教育资源', icon: 'form' }
      // },
      {
        path: '/s/online',
        name: 'sOnline',
        component: () => import('@/views/student/online/index'),
        meta: { title: '教学资源', icon: 'form' }
      },
      {
        path: '/s/resource',
        name: 'resource',
        component: () => import('@/views/student/resource/index'),
        meta: { title: '额外资源', icon: 'form' }
      },
      {
        path: '/s/simi_resource',
        name: 'simi',
        component: () => import('@/views/student/simi_resource/index'),
        meta: { title: '个性化资源', icon: 'form' }
      }
    ]
  },
  {
    path: '/s/talkabout',
    role: 'student',
    component: Layout,
    children: [
      {
        path: '/s/talkabout',
        name: 'sTalkabout',
        component: () => import('@/views/student/talkabout/index'),
        meta: { title: '在线讨论', icon: 'form' }
      }
    ]
  },
  {
    path: '/s/homework',
    redirect: '/s/homework/b',
    name: 'Homework',
    role: 'student',
    component: Layout,
    meta: { title: '作业', icon: 'form' },
    children: [
      {
        path: '/s/homework/b',
        name: 'sExam',
        component: () => import('@/views/student/homework/index'),
        meta: { title: '作业', icon: 'form' }
      }
    ]
  },
  {
    path: '/s/exam',
    redirect: '/s/exam/b',
    name: 'Exam',
    role: 'student',
    component: Layout,
    meta: { title: '考试', icon: 'form' },
    children: [
      {
        path: '/s/exam/b',
        name: 'sExam',
        component: () => import('@/views/student/exam/index'),
        meta: { title: '我的考试', icon: 'form' }
      },
      {
        path: '/s/achievement',
        name: 'sAchievement',
        component: () => import('@/views/student/achievement/index'),
        meta: { title: '成绩管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/s/talkabout',
    role: 'student',
    component: Layout,
    children: [
      {
        path: '/s/collect',
        name: 'sCollect',
        component: () => import('@/views/student/collect/index'),
        meta: { title: '收藏管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/s/feedback',
    role: 'student',
    component: Layout,
    children: [
      {
        path: '/s/feedback',
        name: 'tFeedback',
        component: () => import('@/views/student/feedback/index'),
        meta: { title: '反馈管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/s/info',
    role: 'student',
    hidden: true,
    component: Layout,
    children: [
      {
        path: '/s/info',
        name: 'sInfo',
        component: () => import('@/views/student/info/index'),
        meta: { title: '个人中心', icon: 'form' }
      }
    ]
  },
  {
    path: '/s/changePass',
    role: 'student',
    hidden: true,
    component: Layout,
    children: [
      {
        path: '/s/changePass',
        name: 'schangePass',
        component: () => import('@/views/student/changePass/index'),
        meta: { title: '修改密码', icon: 'form' }
      }
    ]
  },
  {
    path: '/s/homeworkOnLine',
    role: 'student',
    hidden: true,
    component: Layout,
    children: [
      {
        path: '/s/homeworkOnLine',
        name: 'homeworkOnLine',
        component: () => import('@/views/student/homework/index'),
        meta: { title: '作业', icon: 'form' }
      }
    ]
  },
  {
    path: '/s/studentHomeworkOnLine',
    role: 'student',
    hidden: true,
    component: Layout,
    children: [
      {
        path: '/s/studentHomeworkOnLine',
        name: 'studentHomeworkOnLine',
        component: () => import('@/views/student/homework/homeworkOnLine'),
        meta: { title: '作业', icon: 'form' }
      },
      {
        path: '/s/homework/result',
        name: 'sHomeworkResult',
        component: () => import('@/views/student/homework/homeworkResult.vue'),
        meta: { title: '作业查询', icon: 'form' }
      }
    ]
  },
  {
    path: '/s/examOnLine',
    role: 'student',
    hidden: true,
    component: Layout,
    children: [
      {
        path: '/s/examOnLine',
        name: 'examOnLine',
        component: () => import('@/views/student/exam/examOnLine'),
        meta: { title: '考试', icon: 'form' }
      }
    ]
  },
  {
    path: '/s/studentExamOnLine',
    role: 'student',
    hidden: true,
    component: Layout,
    children: [
      {
        path: '/s/studentExamOnLine',
        name: 'studentExamOnLine',
        component: () => import('@/views/student/achievement/examstudent-form'),
        meta: { title: '考试', icon: 'form' }
      }
    ]
  },
  {
    path: '/tb',
    role: 'student',
    hidden: true,
    component: Layout,
    children: [
      {
        path: '/tb',
        name: 'tb',
        component: () => import('@/views/student/talkabout/participate'),
        meta: { title: '讨论详情', icon: 'form' }
      }
    ]
  },
  {
    path: '/pj',
    role: 'student',
    hidden: true,
    component: Layout,
    children: [
      {
        path: '/pj',
        name: 'pj',
        component: () => import('@/views/student/talkabout/pj'),
        meta: { title: '评价详情', icon: 'form' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
